package com.ml.admin.controller;

import com.ml.admin.utils.JwtUtil;
import com.ml.admin.utils.ResponseEnum;
import com.ml.admin.utils.ReturnResponse;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.UnsupportedEncodingException;

/**
 * 统一获取token接口
 * @author ml
 * @date 2023/3/14 15:05
 */
@RestController
@RequestMapping("/token")
public class TokenController {
    @GetMapping("/gettoken")
    public ReturnResponse getToken(String phone) {
        if (StringUtils.isBlank(phone)){
            return ReturnResponse.failure(ResponseEnum.PARAM_NOT_COMPLETE);
        }
        try {
            return ReturnResponse.success(JwtUtil.createToken(phone));
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
            return ReturnResponse.failure(ResponseEnum.FAILURE);
        }
    }
}
